﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TheCell;

namespace SudoForm
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
            this.Initialization();
        }

        private void Initialization()//初始化
        {
            //CellUtils.InitializeCell();
           
            FormUtils.Initialzation(this.panel1, this.GetType(), CellUtils.InitializeCell());
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            List<Cell> cells = new List<Cell>();
            foreach (Control control in this.panel1.Controls)
            {
                TextBox textBox = control as TextBox;
                int line = int.Parse(textBox.Name.Split('-')[0]);
                int col = int.Parse(textBox.Name.Split('-')[1]);
                Cell cell = textBox.Tag as Cell;
                if (!string.IsNullOrEmpty(textBox.Text))
                {
                    cell.Possible = new List<int>() { int.Parse(textBox.Text) };
                    cell.Value = int.Parse(textBox.Text);
                    cell.Status = CellStatus.Fixed;
                }

                cells.Add(cell);
            }
            
            string fileFullPath = @"D:\Code\Sudo\SudoData.json";
            JsonUtils.Serialize(fileFullPath, cells);

            //List<Cell> list = JsonUtils.Deserialize(fileFullPath);
        }   //看清循环确定单步调试位置 

        private void button1_Click(object sender, EventArgs e)
        {
            AnswerForm answer = new AnswerForm();
            answer.ShowDialog();
        }
    }
}
